﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace hse_2013_zavyalovalevina
{
    [Serializable]
    public class Worker : iWorker
    {
        public static List<String> Positions = new List<string>();
        public static List<String> Exp = new List<string>();
        private int position, experience;
        
        public string FullName { get; set; }
        public DateTime BirthDate { get; set; }
        public string Position { get { return Positions[position]; } }
        public string Experience { get { return Exp[experience]; } }
        private string Responsibility { get; set; }
        public int SlavesNumber { get; set; }

        public void ChangePosition(int i) { position = i; }
        public void ChangeExp(int i) { experience = i; }

        public int getPositionIndex() { return position; }
        public int getExperienceIndex() { return experience; }
        public string getResponsibility() { return Responsibility; }

        static Worker()
        {
            string line = "";
            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(@"Positions.txt", Encoding.GetEncoding("windows-1251"));
                while ((line = file.ReadLine()) != null)
                    Positions.Add(line);
                file.Close();
            }
            catch { }

            line = "";
            try
            {
                System.IO.StreamReader file1 = new System.IO.StreamReader(@"Exp.txt", Encoding.GetEncoding("windows-1251"));
                while ((line = file1.ReadLine()) != null)
                    Exp.Add(line);
                file1.Close();
            }
            catch { }

            if (Positions.Count == 0)
                Positions = new List<string> { "Позиция 1", "Позиция 2", "Позиция 3", "Позиция 4", "Позиция 5", "Позиция 6", "Позиция 7" };
            if (Exp.Count == 0)
                Exp = new List<string> { "Позиция 1", "Позиция 2", "Позиция 3", "Позиция 4", "Позиция 5", "Позиция 6", "Позиция 7" };
   
        }
        public Worker(string fullname, string birthdate, int position, int experience, string responsobility, int slavelnumber)
        {
            try
            {
                if (Exp.Count <= experience || Positions.Count <= position)
                    throw new Exception("Ошибка создания объекта");
                this.FullName = fullname;
                this.BirthDate = (DateTime.Parse(birthdate));
                this.position = position;
                this.experience = experience;
                Responsibility = responsobility;
                SlavesNumber = slavelnumber;
            }
            catch(Exception ex)
            {
            }
        }
        public override string ToString() { return String.Format("{0}", FullName); }
    }
}
